package cn.edu.seu.herald.informationplatform.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;
import java.util.Map.Entry;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.edu.seu.herald.informationplatform.bean.league.Activity;
import cn.edu.seu.herald.informationplatform.dao.cookie.LeagueUserSessionCookieAccess;
import cn.edu.seu.herald.informationplatform.dao.database.ActivityDao;
import cn.edu.seu.herald.informationplatform.dao.database.AlbumDao;
import cn.edu.seu.herald.informationplatform.dao.database.MessageDao;

public class MessageDelete extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public MessageDelete() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}
	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		try {
			int messageId = Integer.valueOf(request.getParameter("message"));
			MessageDao messageDao = MessageDao.getDao();
			messageDao.deleteMessage(messageId);
			String leagueId = request.getParameter("league");
			String activityId = request.getParameter("activity");
			String recruitId = request.getParameter("recruit");
			if(activityId!=null){
				response.sendRedirect("./activity.jsp?activity="+Integer.parseInt(activityId)+"&league="+Integer.parseInt(leagueId));
			}else{
				if (recruitId!=null) {
					response.sendRedirect("./recruit.jsp?league="+Integer.parseInt(leagueId));
				}else {
					response.sendRedirect("./guestbook.jsp?league="+Integer.parseInt(leagueId));
				}
			}
		
		}catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occurs
	 */
	public void init() throws ServletException {
		// Put your code here
	}

}
